using Character;
using UnityEngine;

public class JumpConponent : CharacterComponent
{
    [AutoComponent]
    private Rigidbody rb;
    [SerializeField]
    private float jumpHeight = 5f;
    public float JumpHeight
    {
        set => JumpSpeed = Mathf.Sqrt(2 * value * -Physics.gravity.y);
    }
    public float JumpSpeed { get; private set; }

    public void Jump()
    {
        rb.velocity = new Vector3(rb.velocity.x, JumpSpeed, rb.velocity.z);
    }

    public void Jump(float height)
    {
        float speedY = Mathf.Sqrt(2 * height * -Physics.gravity.y);
        rb.velocity = new Vector3(rb.velocity.x, speedY, rb.velocity.z);
    }

    protected override void Awake()
    {
        base.Awake();
        JumpHeight = jumpHeight;
    }

    private void Update()
    {
#if UNITY_EDITOR
        JumpHeight = jumpHeight;
#endif
    }
}
